﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;

using Gift.DAL;
using Gift.Model;

namespace WebSite.cn
{
    public partial class head : System.Web.UI.UserControl
    {


    public readonly BasePage theBase = new BasePage();
       // Fields
    public string headmsg = "";
    public string lan = "";
    public string logo = "";
    public string ShopCount = "0";
    public string shopname = "";
    public string shopurl = "";
    public string TopicHtml = "";
    public string totalprice = "0";
    public string typemsg = "";

    public string LoginMemberName = string.Empty;

    // Methods
    private void Bind()
    {
        if (!string.IsNullOrEmpty(this.headmsg))
        {
            return;
        }
        this.logo = "<img src='../uploadfile/banner/" + info.info1("", "shoplogo") + "' />";
        this.shopname = info.info1("", "shopname");
        this.shopurl = info.info1("", "shopurl");
        string sql = "select classid,classlink,classname from DB_Class where parentid=0 and visible=1 and classname<>'' and (classpcs='顶部' or classpcs='顶部和底部') and languages=1 order by classorder";
        DataTable table = SQLAccess.GreatDs(sql).Tables[0];
        if (table.Rows.Count > 0)
        {
            foreach (DataRow row in table.Rows)
            {
                if (row["classlink"].ToString() != "")
                {
                    if (base.Request.Url.ToString().ToLower().IndexOf(row["classlink"].ToString().ToLower()).ToString() != "-1"
                        || (!string.IsNullOrEmpty(base.Request.QueryString["sid"]) && (base.Request.FilePath + "?sid=" + base.Request.QueryString["sid"]).ToLower().IndexOf(row["classlink"].ToString().ToLower()).ToString() != "-1"))
                    {
                        object obj2 = this.headmsg;
                        this.headmsg = string.Concat(new object[] { obj2, "<li class='currentPage'><a href='", row["classlink"], "'>", row["classname"], "</a></li>" });
                    }
                    else
                    {
                        object obj3 = this.headmsg;
                        this.headmsg = string.Concat(new object[] { obj3, "<li><a href='", row["classlink"], "'>", row["classname"], "</a></li>" });
                    }
                    continue;
                }
                if (base.Request.QueryString["cid"] != null)
                {
                    if (base.Request.QueryString["cid"].ToString() == row["classid"].ToString())
                    {
                        object obj4 = this.headmsg;
                        this.headmsg = string.Concat(new object[] { obj4, "<li class='currentPage'><a href='content.aspx?cid=", row["classid"], "'>", row["classname"], "</a></li>" });
                    }
                    else
                    {
                        object obj5 = this.headmsg;
                        this.headmsg = string.Concat(new object[] { obj5, "<li><a href='content.aspx?cid=", row["classid"], "'>", row["classname"], "</a></li>" });
                    }
                    continue;
                }
                object headmsg = this.headmsg;
                this.headmsg = string.Concat(new object[] { headmsg, "<li><a href='content.aspx?cid=", row["classid"], "'>", row["classname"], "</a></li>" });
            }
        }
        if ((re.ReadCookie("tempno") != null) && (re.ReadCookie("tempno") != "") || theBase.LoginMember != null)
        {
            string tempId;
           if (theBase.LoginMember != null)
            {
                tempId = theBase.LoginMember.MemberId.ToString();
            }
            else
            {
                tempId = re.ReadCookie("tempno");
            }
            DataTable table2 = SQLAccess.GreatDs("select DB_Car.carid,DB_Car.pronum,DB_Car.price,DB_Car.sumprice,DB_Car.contents,DB_Shoppro.typeid,DB_Shoppro.proname,DB_Shoppro.proprice1,DB_Shoppro.propic2,DB_Shoppro.proid  from DB_Car inner join DB_Shoppro on DB_Car.productid=DB_Shoppro.proid where DB_Car.flag=0 and DB_Car.temp='" +  tempId + "'").Tables[0];
            this.ShopCount = table2.Rows.Count.ToString();
            if (table2.Rows.Count > 0)
            {
                foreach (DataRow row2 in table2.Rows)
                {
                    this.totalprice = string.Format("{0:f}", Convert.ToSingle(row2["sumprice"]) + Convert.ToSingle(this.totalprice));
                }
            }
        }
        string str3 = "select classid,classname from DB_Productclass where parentid=0 and visible=1 order by classorder";
        DataTable table3 = SQLAccess.GreatDs(str3).Tables[0];
        if (table3.Rows.Count > 0)
        {
            foreach (DataRow row3 in table3.Rows)
            {
                string typemsg = this.typemsg;
                this.typemsg = typemsg + "<option value=" + row3["classid"].ToString() + ">" + row3["classname"].ToString() + "</option>";
            }
        }
      //  str3 = "select topicid,pic,picurl from DB_topic where visible=1 order by topicorder asc";
      
        DataTable table4 = new DALTopic().GetLitstByPageAndDirection("首页", "横向");
        if (table4 != null && table4.Rows.Count > 0)
        {
            if (table4.Rows[0]["picurl"].ToString() != "")
            {

                TopicHtml = "<a href='" + table4.Rows[0]["picurl"].ToString() + "?tid=" + table4.Rows[0]["topicid"].ToString() + "' target='_blank'><img src='../uploadFile/topic/"
                    + table4.Rows[0]["pic"].ToString() + "' border='0' width='965px' /></a>";
            }
            else
            {
                TopicHtml = "<img src='../uploadFile/topic/"
                    + table4.Rows[0]["pic"].ToString() + "' border='0' width='965px' />";
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

        if (theBase.SessionSearchKeyWords != null)
            {
                this.txtKeyName.Value = theBase.SessionSearchKeyWords;
            }

            DB_Member oMember = new BasePage().LoginMember;
            if (oMember != null)
            {
                LoginMemberName = oMember.LoginName; 
            }

           this.Bind();


    }


}

}